package com.andy.blog.admin.service.impl;

import com.andy.blog.admin.dto.FriendDTO;
import com.andy.blog.admin.service.FriendBusService;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.utils.TransformUtils;
import com.andy.blog.dal.domain.FriendDO;
import com.andy.blog.dal.service.FriendDalService;
import com.andy.blog.dal.vo.FriendVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2023/7/30 15:22
 */
@Service
public class FriendBusServiceImpl implements FriendBusService {

    @Resource
    private FriendDalService friendDalService;

    @Override
    public List<FriendDTO> listFriend(FriendVO friendVO) {
        List<FriendDO> friendDOList = friendDalService.selectList(friendVO);
        return TransformUtils.transformList(friendDOList, FriendDTO.class);
    }

    @Override
    public PageUtilsDTO<FriendDTO> listFriendByPage(FriendVO friendVO) {
        IPage<FriendDO> friendDOIPage = friendDalService.selectListByPage(friendVO);

        return PageUtilsDTO.build(friendDOIPage.getTotal(), TransformUtils.transformList(friendDOIPage.getRecords(), FriendDTO.class));
    }

    @Override
    public void addFriend(FriendVO friendVO) {
        friendDalService.insertFriend(friendVO);
    }

    @Override
    public void editFriend(FriendVO friendVO) {
        friendDalService.updateFriend(friendVO);
    }

    @Override
    public FriendDTO selectById(Long id) {
        FriendDO friendDO = friendDalService.selectById(id);
        return TransformUtils.transform(friendDO, FriendDTO.class);
    }
}
